package cn.edu.swu.myapplication1

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Button

class SecondActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.second_layout)
        val data1 = intent.getStringExtra("extra_data")
        Log.d("SecondActivity", "$data1")
        val bcButton: Button = findViewById(R.id.backTo1)
        bcButton.setOnClickListener {
            val intent = Intent()
            intent.putExtra("back_data", "button_return_from2")
            setResult(RESULT_OK, intent)
            finish()
        }
    }

    // 通过back键返回数据给a1
    override fun onBackPressed() {
        val intent = Intent()
        intent.putExtra("back_data", "back_return_from2")
        setResult(RESULT_OK, intent)
        finish()

    }
}